create or replace function random_query(STEP INT)
returns void
AS
$$
DECLARE
	minX float8; 	minY float8;
	maxX float8;	maxY float8;
	width_ float8;	height_ float8;
	centerx float8;	centery float8;
	randomx float8; randomy float8;
	stepX float8;	stepY float8;
	step_ int;
    boxMinX float8;    boxMaxX float8;
    boxMinY float8;    boxMaxY float8;
BEGIN
	minX = 12843486;  minY = 4781532;
    maxX = 13080040;   maxY = 5024640;

	width_ = maxX - minX;   	height_ = maxY - minY;
    step_ := STEP;
 	SELECT ceil(random()*(step_ -1)+1) into randomx;
	SELECT ceil(random()*(step_ -1)+1) into randomy;
   	centerx = minX + width_ * 0.5 + randomx;
   	centery = minY + height_ * 0.5 + randomy;
   	stepX = width_ * 0.05;
   	stepY = height_ * 0.05;

    boxMinX = centerx - stepX;    boxMinY = centery - stepY;
    boxMaxX = centerx + stepX;    boxMaxY = centery + stepY;

    PERFORM smgeometry from public.landuse where smgeometry &&
    st_makeenvelope(boxMinX, boxMinY, boxMaxX, boxMaxY, 4326);
END;
$$ LANGUAGE 'plpgsql';